-
Notifications
You must be signed in to change notification settings - Fork 22.7k
fit-content: explain browser computation #39730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -9,6 +9,10 @@ browser-compat: css.properties.width.fit-content | |||
|
|||
The **`fit-content`** keyword is equivalent to {{cssxref("fit-content_function", "fit-content(stretch)")}}. In practice, this means that the box will use the available space, but never more than {{cssxref("max-content")}}. | |||
|
|||
It calculates the size using the below equation: | |||
|
|||
fit-content size = min(max-content,max(min-content,available-space)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
fit-content size = min(max-content,max(min-content,available-space)) | |
fit-content size = min(max-content,max(min-content,available-space)) |
Preview URLs (comment last updated: 2025-06-01 04:47:42) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR. I made some suggestions for the comment to better fit general MDN writing styles. To created "code" in markdown, add a back tick (`) before an after the text you want to style as code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Also, congratulations on your first merged MDN content PR. Welcome to he team!
Description
The fit-content operates using an intelligent clamping mechanism. It computes the size of an element using the following logic:
fit-content size=min(max-content,max(min-content,available-space))
Motivation
The current description of fit-content does not clearly explain how its sizing logic works internally. This update introduces a concise explanation of the clamping mechanism behind fit-content, including the formula used to compute the final size. It helps developers better understand how the function balances content size and available space, especially in responsive layouts.
Additional details
https://developer.mozilla.org/en-US/docs/Web/CSS/fit-content
Related issues and pull requests